<!-- 分销、分红佣金提现 + 分红奖金提现 -->
<template>
	<view v-if="init">
		<u-tabs v-if="vuex_user.type == 4" :list="tabList" :is-scroll="false" @change="tabChange" :current="currentType"
			:active-color="vuex_config.themeColor1" :bar-width="80"></u-tabs>
		<withd-drawal :currentType="currentType"></withd-drawal>
	</view>
</template>

<script>
	import withdDrawal from '../components/withdDrawal.vue'
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				tabList: [{
						name: `佣金￥（${0})`,
					},
					{
						name: `奖金￥（${0})`
					},
				],
				currentType: 0, // 0:佣金 1：奖金
				init: false
			};
		},
		components: {
			'withd-drawal': withdDrawal
		},
		computed: {
			...mapState(['vuex_count']),
		},
		onLoad() {
			this.changeTab()
			this.init = true
			this.getInfo()
		},
		methods: {
			...mapActions(['loadUserCount', 'loadBusinessInfo']),
			changeTab() {
				if (this.vuex_user.type == 4) {
					let reg = /[0-9]+(\.[0-9]{1,2})?/
					let num = this.vuex_count.bonus_balance_sum - this.vuex_count.bonus_withdrawal
					num = num > 0 ? num : 0
					let arr1 = reg.exec(num)
					let arr2 = reg.exec(this.vuex_count.sure_cash || 0)
					this.tabList[0].name = `佣金(￥${arr2 && arr2[0] ? arr2[0] : 0})`
					this.tabList[1].name = `奖金(￥${arr1 && arr1[0] ? arr1[0] : 0})`
				}
			},
			// 查询个人统计
			getInfo() {
				this.$loading()
				this.loadUserCount().then(() => {
					this.changeTab()
					this.loadBusinessInfo()
					this.$hide()
				}).catch(() => {
					this.$hide()
				})
			},
			tabChange(index) {
				if (this.currentType !== index) {
					this.currentType = index
				}
			},
		}
	};
</script>

<style lang="scss" scoped>

</style>
